import axios from 'axios'

let util = {

    /**
     * 获得一个随机数[minNum, maxNum)
     * @param minNum 最大值
     * @param maxNum 最小值
     * @returns {number}
     */
    randomNum: function (minNum, maxNum) {
        switch (arguments.length) {
            case 1:
                return parseInt(Math.random() * minNum, 10);
            case 2:
                return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
            default:
                return 0;
        }
    },

    /**
     * 判断设备是不是手机
     * @returns {RegExpMatchArray}
     */
    isMobile() {
        return navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
    },

    vibrate(arg) {
        if (navigator !== undefined && typeof (navigator.vibrate) === 'function') {
            navigator.vibrate(arg);
        }
    },

    getIpInfo() {
        axios.get('http://pv.sohu.com/cityjson?ie=utf-8').then((response) => {
            console.log(response);
        })
        axios.get('http://fw.qq.com/ipaddress').then((response) => {
            console.log(response);
        })
    }

};
export default util;
